Skip to content

Conversation

@rcst
Copy link

@rcst rcst commented Nov 25, 2025

Summary

This PR fixes the namespacing issue described in #100 where update_rank_list() fails inside Shiny modules because nested rank-list element IDs are not correctly namespaced.

Background

Shiny namespacing applies only to top-level input IDs and does not automatically propagate to nested widget element IDs inside inputMessages. As a result, rank-list updates were being sent to non-namespaced DOM IDs, and the client-side binding could not locate the correct list container.

What this PR changes

  • as_rank_list_id() is updated to append the module namespace (id) instead of prepending it.
  • The widget's JavaScript binding is updated so that setValue() correctly applies the namespace to inputIDs inside the message object. update_rank_list() explicitly stores the namespace of it's session into the message object, so that the shiny binding can apply it.

Why this works

With this fix:

  • Shiny's session$ns() becomes compatible with sortable’s internal ID patterns.
  • update_rank_list() correctly updates the UI inside modules.
  • No behavior changes occur for non-module contexts.

Related Issue

Fixes #100

This commit addresses Issue rstudio#100. The rank-list widget currently does not
get updated when used within a Shiny module.
Shiny.sendInputMessage(inputID, message) automatically applies
namespacing to inputID (the first parameter), however the widget
consists of 2 nested HTML-IDs - the rank-list container and the actual
list. Shiny.sendInputMessage only applies namespacing to the
provided inputID, but not to inputIDs contained inside
the message list-object. In `update_rank_list()`, the way that the
provided inputID is processed will make it refer to the container's ID.
The rank-list input binding's setValue function has been changed to take
this into account and now adds any namespace prefix to the nested input
ID. To do this, the namespace has been added explicitly to the message
list-object in `update_rank_list()`.
Also, `as_rank_list_id()` and `as_bucket_list_id()` both now append
(instead of prepend) "-rank-list" to enable Shiny module namespacing as
suggested in the respective comment in `methods.R`.

Changes:
- Updated as_rank_list_id() append "-rank-list" to provided ID.
- Improve rank-list JS binding to correctly apply namespacing to
  the input ID within the message object itself

Fixes rstudio#100
@CLAassistant
Copy link

CLAassistant commented Nov 25, 2025

CLA assistant check
All committers have signed the CLA.

@andrie
Copy link
Member

andrie commented Dec 7, 2025

Thank you for this contribution.

We will be using the solution in #127 instead.

I appreciate your time and effort.

@andrie andrie closed this Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants